#!/bin/bash
echo "curl download repo tool from ustc mirror "
curl -sSL  'https://gerrit-googlesource.proxy.ustclug.org/git-repo/+/master/repo?format=TEXT' |base64 -d > ~/bin/repo-ustc
chmod a+x ~/bin/repo-ustc

echo "Replace google url to aosp url address "
sed 's/https:\/\/gerrit.googlesource.com\/git-repo/https:\/\/gerrit-googlesource.proxy.ustclug.org\/git-repo/g' ~/bin/repo-ustc > ~/bin/repo

if [[ ! -d "$HOME/aosp"  ]]; then
    echo "Error: Directory aosp does not exists and create."
    mkdir $HOME/aosp
fi
echo "Enter into aosp dircetorcd $HOME/aosp"
cd $HOME/aosp
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-10.0.0_r2
repo sync -c
